package com.shopmall.manager.controller;

import com.github.pagehelper.PageInfo;
import com.shopmall.common.log.annotation.Log;
import com.shopmall.common.log.enums.OperatorType;
import com.shopmall.manager.service.BrandService;
import com.shopmall.model.entity.product.Brand;
import com.shopmall.model.vo.common.Result;
import com.shopmall.model.vo.common.ResultCodeEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/product/brand")
public class BrandController {
    @Autowired
    private BrandService brandService;

    // 查询所有品牌
    @GetMapping("findAll")
    public Result<List<Brand>> findAll() {
        List<Brand> list = brandService.findAll();
        return Result.build(list, ResultCodeEnum.SUCCESS);
    }

    // 列表
    @Log(title = "品牌管理：列表", businessType = 0, operatorType = OperatorType.OTHER)
    @GetMapping("/{page}/{limit}")
    public Result<PageInfo<Brand>> list(@PathVariable Integer page,
                                        @PathVariable Integer limit) {
        PageInfo<Brand> pageInfo = brandService.findByPage(page, limit);
        return Result.build(pageInfo, ResultCodeEnum.SUCCESS);
    }

    // 添加
    @PostMapping("/save")
    public Result<String> save(@RequestBody Brand brand) {
        String flag = brandService.save(brand);
        return Result.build(flag, ResultCodeEnum.SUCCESS);
    }
}
